---
import BaseHead from '../components/Head/BaseHead.astro';
import Nav from '../components/Nav.astro';
import Card from '../components/Card.astro';
import Footer from '../components/Footer/Footer.astro'

// export interface Props {
//     categoryId: Int16Array;
// }

// const { categoryId } = Astro.props;

let categoryId = Astro.url.searchParams.get('post');

const title = '觅心阁 MXG';
const seoDescription = '一个个人博客网站, 用于分享日常';

const response = await fetch(`http://localhost:9901/api/getArticlesByCategoryId?id=${categoryId}`);
const data = await response.json();

const sortedPosts = data.sort((a, b) => new Date(b.views).valueOf() - new Date(a.views).valueOf());
---

<html lang="zh">

<head>
  <BaseHead title={title} description={seoDescription} />
</head>

<body class="bg-white text-black font-body leading-normal personality-casual">
  <Nav />

  <main class="py-12 lg:py-20">
    <article class="max-w-6xl mx-auto px-3">
      <section class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 py-8" data-test="articles-section">
        {sortedPosts.slice(0, 9).map(p => <div class="col-span-1">
          <Card post={p} />
        </div>)}
      </section>
    </article>
  </main>
  <Footer />
</body>

</html>



